<template>
    <a-form layout="inline">
        <a-row :gutter="48">
            <a-col :md="8" :sm="24">
                <a-form-item label="查询范围">
                    <a-select v-if="members" v-model="params.evaluated" placeholder="请选择" default-value="0">
                        <a-select-option value="0">全部</a-select-option>
                        <a-select-option value="1">未评价</a-select-option>
                        <a-select-option value="2">院级未评价</a-select-option>
                        <a-select-option value="3">系级未评价</a-select-option>
                        <a-select-option value="4">无效简历</a-select-option>
                    </a-select>
                    <a-select v-else v-model="params.evaluated" placeholder="请选择" default-value="2">
                        <a-select-option value="0">全部</a-select-option>
                        <a-select-option value="1">已评价</a-select-option>
                        <a-select-option value="2">未评价</a-select-option>
                    </a-select>
                </a-form-item>
            </a-col>
            <a-col v-if="positions && positions.length > 0" :md="8" :sm="24">
                <a-form-item label="岗位筛选">
                    <a-select v-model="params.positionIds" placeholder="请选择" mode="multiple">
                        <a-select-option v-for="(item, index) in positions" :key="index"
                                         :value="item.id">{{item.name}}</a-select-option>
                    </a-select>
                </a-form-item>
            </a-col>
            <template v-if="advanced">
                <a-col :md="8" :sm="24">
                    <a-form-item label="姓名">
                        <a-input v-model="params.name" placeholder=""/>
                    </a-form-item>
                </a-col>
                <a-col :md="8" :sm="24">
                    <a-form-item label="面试状态">
                        <a-select v-model="params.interviewStatus" placeholder="请选择" mode="multiple" :allowClear="true">
                            <a-select-option value="0">未安排</a-select-option>
                            <a-select-option value="1">待面试</a-select-option>
                            <a-select-option value="-1">不安排</a-select-option>
                            <a-select-option value="2">通过面试</a-select-option>
                            <a-select-option value="-2">面试失败</a-select-option>
                            <a-select-option value="-3">拒绝面试</a-select-option>
                        </a-select>
                    </a-form-item>
                </a-col>
                <a-col :md="8" :sm="24">
                    <a-form-item label="面试时间">
                        <a-range-picker class="full-item" v-model="params.interviewTime"/>
                    </a-form-item>
                </a-col>
                <a-col :md="8" :sm="24" v-if="members">
                    <a-form-item label="面试操作员">
                        <a-select v-model="params.interviewHandlerId" placeholder="请选择" :allowClear="true">
                            <a-select-option v-for="(item, index) in members" :key="index"
                                             :value="item.id">{{item.name}}</a-select-option>
                        </a-select>
                    </a-form-item>
                </a-col>
                <a-col :md="8" :sm="24">
                    <a-form-item label="签约状态">
                        <a-select v-model="params.signStatus" placeholder="请选择" mode="multiple" :allowClear="true">
                            <a-select-option value="0">未记录</a-select-option>
                            <a-select-option value="1">待签约</a-select-option>
                            <a-select-option value="-1">拒绝录用</a-select-option>
                            <a-select-option value="2">已签约</a-select-option>
                            <a-select-option value="-2">拒绝签约</a-select-option>
                        </a-select>
                    </a-form-item>
                </a-col>
                <a-col :md="8" :sm="24">
                    <a-form-item label="签约时间">
                        <a-range-picker class="full-item" v-model="params.signTime"/>
                    </a-form-item>
                </a-col>
                <a-col :md="8" :sm="24" v-if="members">
                    <a-form-item label="签约操作员">
                        <a-select v-model="params.signHandlerId" placeholder="请选择" :allowClear="true">
                            <a-select-option v-for="(item, index) in members" :key="index"
                                             :value="item.id">{{item.name}}</a-select-option>
                        </a-select>
                    </a-form-item>
                </a-col>
                <a-col :md="8" :sm="24">
                    <a-form-item label="创建时间">
                        <a-range-picker class="full-item" v-model="params.createTime"/>
                    </a-form-item>
                </a-col>
            </template>
            <a-col :md="!advanced && 8 || 24" :sm="24">
              <span class="table-page-search-submitButtons"
                    :style="advanced && { float: 'right', overflow: 'hidden' } || {} ">
                <a-button type="primary" @click="query" :loading="loading">查询</a-button>
                <a-button style="margin-left: 8px" @click="params = {}">重置</a-button>
                <a @click="advanced = !advanced" style="margin-left: 8px">
                  {{ advanced ? '收起' : '展开' }}
                  <a-icon :type="advanced ? 'up' : 'down'"/>
                </a>
              </span>
            </a-col>
        </a-row>
    </a-form>
</template>

<script>
    export default {
        name: "ResumeFilter",
        props: {
            members: {
                type: Array,
                default: () => null
            },
            positions: {
                type: Array,
                default: () => null
            },
            loading: {
                type: Boolean,
                default: false
            }
        },
        data() {
            return {
                advanced: false,
                params: {
                    evaluated: this.members ? "0" : "2"
                }
            }
        },
        methods: {
            query() {
                this.parseTime('interviewTime')
                this.parseTime('signTime')
                this.parseTime('createTime')
                this.$emit('query', this.params)
            },
            parseTime(key) {
                let legal = this.params[key] && this.params[key].length === 2
                this.params[key + 'Begin'] = legal && this.params[key][0].valueOf() || null
                this.params[key + 'End'] = legal && this.params[key][1].valueOf() || null
            }
        }
    }
</script>
